package com.zsn.demo.test.threadPool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zsn
 * @CreateTime: 2022/12/15 1:17
 * @Description:
 */
public class ThreadPoolTest1 {

    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);


//        scheduledExecutorService.schedule(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println(Thread.currentThread().getId() + "---" + System.currentTimeMillis());
//            }
//        },2, TimeUnit.SECONDS);

        //以固定的频率执行任务,开启任务的时间是固定的, 在 3 秒后执行任务,以后每隔 5 秒重新执行一次
        System.out.println(args);

        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
             @Override
             public void run() {
                 System.out.println(Thread.currentThread().getId() + "以固定頻率開啓任務" + System.currentTimeMillis());
             }
         },3,5,TimeUnit.SECONDS
        );
    }
}

